########### 基本配置 ################

# 添加第二个前缀键 Ctrl-a
set -g prefix2 C-a                        # GNU-Screen compatible prefix

# 设置前缀键为 Ctrl-a
# unbind C-b
# set -g prefix C-a
# bind C-a send-prefix

# 启用鼠标支持
# 设置窗口和面板的起始索引为1
set -g base-index 1
# 启用256色支持
set -g default-terminal "screen-256color"
set -g display-panes-time 800 # slightly longer pane indicators display time
set -g display-time 1000      # slightly longer status messages display time
set -g history-limit 50000
set -g mouse on
# activity
set -g monitor-activity on
set -g renumber-windows on    # renumber windows when a window is closed
# 设置面板边框颜色
set -g pane-border-style fg=cyan
set -g pane-active-border-style fg=green
set -g set-titles on          # set terminal title
# 设置状态栏
set -g status on
# 设置整个状态栏背景颜色 bg(背景色) fg(前景色)
# set -g status-style "bg=#882244"
# 分别设置状态栏左右颜色
# set -g status-left "bg=#3a3a3a"
# set -g status-left "fg=#bcbcbc"
set -g status-interval 1
set -g status-justify left
set -g status-left-length 20
set -g status-right-length 50
# set -g status-left "#[fg=green]#H #[fg=white]• #[fg=blue]#S"
# set -g status-right "#[fg=cyan]%Y-%m-%d %H:%M"
set -g visual-activity on


## 窗口选项
setw -g automatic-rename on   # rename window to reflect current program
setw -g pane-base-index 1
# 设置窗口列表样式
# setw -g window-status-format "<#[fg=white](#I):#[fg=cyan]#W>"
# setw -g window-status-current-format "#[fg=white]<(#I):#[fg=cyan]#W#[fg=white]•>"
# 设置复制模式为 vi 模式
setw -g mode-keys vi
setw -g xterm-keys on

# 会话选项
set -s escape-time 10                     # faster command sequences
set -sg repeat-time 600                   # increase repeat timeout
set -s focus-events on

# set -q -g status-utf8 on                  # expect UTF-8 (tmux < 2.2)
setw -q -g utf8 on

set -g history-limit 5000                 # boost history

# 绑定快捷键
bind    Tab         last-window        # move to last active window
bind    C-a         send-prefix -2
# clear both screen and history
bind -n C-l         send-keys C-l \; run 'sleep 0.1' \; clear-history
# create session
bind    C-c         new-session
# find session
bind    C-f         command-prompt -p find-session 'switch-client -t %%'
bind    C-n         next-window
bind    C-p         previous-window
# split current window horizontally
bind    -           split-window -v
# split current window vertically
bind    _           split-window -h
bind    e           new-window -n "~/.tmux.conf.local" "sh -c '\${EDITOR:-vim} ~/.tmux.conf.local && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\"'"
# reload configuration
bind    r           source-file ~/.config/tmux/tmux.conf \; display '~/.config/tmux/tmux.conf sourced'
# window navigation
# unbind  n
# unbind  p
# pane navigation
# bind -n M-Left      select-pane -L
# bind -n M-Right     select-pane -R
# bind -n M-Up        select-pane -U
# bind -n M-Down      select-pane -D
bind -r h           select-pane -L  # move left
bind -r j           select-pane -D  # move down
bind -r k           select-pane -U  # move up
bind -r l           select-pane -R  # move right
bind    >           swap-pane -D       # swap current pane with the next one
bind    <           swap-pane -U       # swap current pane with the previous one
# maximize current pane
bind    +           run 'cut -c3- ~/.tmux.conf | sh -s _maximize_pane "#{session_name}" #D'
# pane resizing
bind -r H           resize-pane -L 2
bind -r J           resize-pane -D 2
bind -r K           resize-pane -U 2
bind -r L           resize-pane -R 2
bind -r C-h         previous-window # select previous window
bind -r C-l         next-window     # select next window
# toggle mouse
bind    m           run "cut -c3- ~/.tmux.conf | sh -s _toggle_mouse"
# -- urlview -------------------------------------------------------------------
bind    U           run "cut -c3- ~/.tmux.conf | sh -s _urlview #{pane_id}"
# -- facebook pathpicker -------------------------------------------------------
bind    F           run "cut -c3- ~/.tmux.conf | sh -s _fpp #{pane_id}"
# -- buffers -------------------------------------------------------------------
bind    b list-buffers  # list paste buffers
bind    p paste-buffer  # paste from the top paste buffer
bind    P choose-buffer # choose which buffer to paste from

# status left/right sections separators
# tmux_conf_theme_left_separator_main=""
# tmux_conf_theme_left_separator_sub="|"
# tmux_conf_theme_right_separator_main=""
# tmux_conf_theme_right_separator_sub="|"
# tmux_conf_theme_left_separator_main='\uE0B0'  # /!\ you don't need to install Powerline
# tmux_conf_theme_left_separator_sub='\uE0B1'   #   you only need fonts patched with
# tmux_conf_theme_right_separator_main='\uE0B2' #   Powerline symbols or the standalone
# tmux_conf_theme_right_separator_sub='\uE0B3'  #   PowerlineSymbols.otf font, see README.md

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'erikw/tmux-powerline'
set -g @tmux_powerline_theme 'default'
set -g @tmux_powerline_segment_lan_ip 'false'
set -g @tmux_powerline_segment_wan_ip 'false'


if '[ ! -d ~/.config/tmux/plugins ]' 'run -b mkdir  ~/.config/tmux/plugins'
if '[ ! -d ~/.config/tmux/plugins/tpm ]' 'run -b "git clone https://github.com/tmux-plugins/tpm  ~/.config/tmux/plugins/tpm"'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.config/tmux/plugins/tpm/tpm'
run '~/.config/tmux/plugins/tmux-powerline/main.tmux'


